/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainPanel.java
 *
 * Created on Jun 28, 2011, 5:02:24 PM
 */
package projetocompiladores;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author gtavcs
 */
public class MainPanel extends javax.swing.JFrame {

    /** Creates new form MainPanel */
    public MainPanel() {
        initComponents();
        run();         
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        scrollPane1 = new java.awt.ScrollPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(323, Short.MAX_VALUE)
                .addComponent(scrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(scrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 364, Short.MAX_VALUE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.ScrollPane scrollPane1;
    // End of variables declaration//GEN-END:variables

    private void run() {

//        Drawing drawing = new DefaultDrawing();
//
//        Figure decisionStatement = StatementFigureUtils.createIfStatementFigure("if x > 12",
//                new Point2D.Double(105, 20));
//        drawing.add(decisionStatement);
//
//        Figure trueOption = StatementFigureUtils.createNormalStatementFigure("x := 10",
//                new Point2D.Double(10, 80));
//        drawing.add(trueOption);
//
//        Figure falseOption = StatementFigureUtils.createNormalStatementFigure("x := 15",
//                new Point2D.Double(220, 80));
//        drawing.add(falseOption);
//
//        StatementFigureUtils.connectFiguresToIfStatement(drawing, decisionStatement, trueOption, falseOption);
//
//        Figure anotherStatement = StatementFigureUtils.createNormalStatementFigure("x := 12",
//                new Point2D.Double(105, 180));
//        drawing.add(anotherStatement);
//
//        StatementFigureUtils.createJunctionFigure(drawing,
//                new Figure[]{trueOption, falseOption},
//                anotherStatement);
//
//        // Create a frame with a drawing view and a drawing editor
//        JFrame f = new JFrame("My Drawing");
//        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//        f.setSize(400, 300);
//        DrawingView view = new DefaultDrawingView();
//        view.setDrawing(drawing);
//        f.add(view.getComponent());
//        f.setVisible(true);

        CommandsGraphFigure commandsGraphFigure = new CommandsGraphFigure();
        try {
            commandsGraphFigure.runAnalisadores();
            this.scrollPane1.add(commandsGraphFigure.createPanel());
            this.setSize(500, 500);
            this.setVisible(true);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(CommandsGraphFigure.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CommandsGraphFigure.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
